<template>
  <!-- 根组件 -->
  <el-dialog title="删除" :visible.sync="dialog" width="30%">
    <span>您是否要删除该用户的所有数据信息?</span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialog = false">取 消</el-button>
      <el-button type="primary" @click="dels">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: '',
  components: {},
  data () {
    return {
      dialog: false,
      userId: 0
    }
  },
  methods: {
    // 弹窗打开
    openDialog (data) {
      this.dialog = data[0]
      this.userId = data[1]
    }, // 弹窗关闭
    closeDialog () {
      this.$refs.userInfoForm.resetFields()
    },
    // 删除用户
    async dels () {
      const { data: res } = await this.axios.delete('users/' + this.userId)
      if (res.meta.status !== 200) {
        this.$message.error(res.meta.msg)
      } else {
        this.$message.success(res.meta.msg)
        // 关闭弹窗
        this.dialog = false
        // 重新获取数据
        this.$parent.getUserList()
      }
    }
  }
}
</script>

<style scoped></style>
